import { createRouter, createWebHashHistory } from "vue-router";
import { components } from "@/config/components";

import type { RouteRecordRaw } from "vue-router";
import type { CompKey, PathType } from "@/config/components";

const {
  Md5,
  Base64,
  RSA,
  AES,
  Markdown,
  JsonVisual,
  WebEditor,
  RegExp,
  Diff,
  RelationCalc,
  UppercaseCalc,
  ImgConvertBase64,
  JsConfuse,
  GenerateQrcode,
  DrawingBoard,
  WebVideo,
  OCR,
  FileOperator,
  JsonToType,
  TextToUnionType,
  ExcelToJson,
  GenerateTemplateFile,
  ChineseToPinyin,
} = components;

// 功能页面
const featurePageChlidren: Array<RouteRecordRaw & { path: PathType; name: CompKey }> = [
  { path: "md5", name: "Md5", component: Md5 },
  { path: "base64", name: "Base64", component: Base64 },
  { path: "rsa", name: "RSA", component: RSA },
  { path: "aes", name: "AES", component: AES },
  { path: "markdown", name: "Markdown", component: Markdown },
  { path: "jsonVisual", name: "JsonVisual", component: JsonVisual },
  { path: "webEditor", name: "WebEditor", component: WebEditor },
  { path: "regExp", name: "RegExp", component: RegExp },
  { path: "diff", name: "Diff", component: Diff },
  { path: "relationCalc", name: "RelationCalc", component: RelationCalc },
  { path: "uppercaseCalc", name: "UppercaseCalc", component: UppercaseCalc },
  { path: "imgConvertBase64", name: "ImgConvertBase64", component: ImgConvertBase64 },
  { path: "jsConfuse", name: "JsConfuse", component: JsConfuse },
  { path: "generateQrcode", name: "GenerateQrcode", component: GenerateQrcode },
  { path: "drawingBoard", name: "DrawingBoard", component: DrawingBoard },
  { path: "webVideo", name: "WebVideo", component: WebVideo },
  { path: "ocr", name: "OCR", component: OCR },
  { path: "fileOperator", name: "FileOperator", component: FileOperator },
  { path: "jsonToType", name: "JsonToType", component: JsonToType },
  { path: "textToUnionType", name: "TextToUnionType", component: TextToUnionType },
  { path: "excelToJson", name: "ExcelToJson", component: ExcelToJson },
  { path: "generateTemplateFile", name: "GenerateTemplateFile", component: GenerateTemplateFile },
  { path: "chineseToPinyin", name: "ChineseToPinyin", component: ChineseToPinyin }
];

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: "/home",
      name: "Home",
      component: () => import("@/pages/Home.vue")
    },
    {
      path: "/featurePage",
      name: "FeaturePage",
      component: () => import("@/pages/FeaturePage.vue"),
      children: featurePageChlidren
    },
    {
      path: "/",
      redirect: { name: "Home" }
    },
    {
      path: "/:pathMatch(.*)",
      name: "NotFound",
      component: () => import("@/pages/NotFound.vue")
    }
  ]
});

export default router;
